package com.syh.app.basic;

import android.app.Application;
import android.content.Context;

import androidx.annotation.NonNull;

import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.request.target.ViewTarget;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshFooter;
import com.scwang.smart.refresh.layout.api.RefreshHeader;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.DefaultRefreshFooterCreator;
import com.scwang.smart.refresh.layout.listener.DefaultRefreshHeaderCreator;
import com.uuzuche.lib_zxing.activity.ZXingLibrary;

import update.UpdateAppUtils;


/**
 * 创建者：SYH
 * 时间：2019/9/26 14:26
 * 编辑者：SYH、
 * 补充说明：application 基类   用于一些必要的初始化工作
 */
public class App extends Application {
    protected static App mApplication;
    private boolean isServiceAlive = false;

    @Override
    public void onCreate() {
        super.onCreate();
        mApplication = this;

        if (BuildConfig.DEBUG) {
            ARouter.openLog();     // 打印日志
            ARouter.openDebug();   // 开启调试模式(如果在InstantRun模式下运行，必须开启调试模式！线上版本需要关闭,否则有安全风险)
        }
        ARouter.init(this);

        ZXingLibrary.initDisplayOpinion(this);

        UpdateAppUtils.init(this);//升级工具初始化

        ViewTarget.setTagId(R.id.glide_tag);//glide 报一个未知错误
    }


    public static App getApplication() {
        return mApplication;
    }

    public void setServiceAlive(boolean isServiceAlive){
        this.isServiceAlive = isServiceAlive;
    }

    public boolean isServiceAlive() {
        return isServiceAlive;
    }

    static {
        //设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
            @Override
            public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
                layout.setPrimaryColorsId(R.color.transparent,R.color.textColor3);//全局设置主题颜色
                return new ClassicsHeader(context);//.setTimeFormat(new DynamicTimeFormat("更新于 %s"));//指定为经典Header，默认是 贝塞尔雷达Header
            }
        });

        SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
            @NonNull
            @Override
            public RefreshFooter createRefreshFooter(@NonNull Context context, @NonNull RefreshLayout layout) {
                layout.setPrimaryColorsId(R.color.transparent,R.color.textColor3);//全局设置主题颜色
                return new ClassicsFooter(context);
            }
        });
    }
}
